﻿// Doc-Encode UTF8-BOM, Space(4), Unix(LF)
#include "hiobj.h"
#include "hiobj_in.h"
#include "hiobj_help.h"
#include "himpp_extension.h"
#include "klbutil/CMap.hpp"
#include <assert.h>

#include "hi_comm_vi.h"


//////////////////////////////////////////////////////////////////////////


// VI_DEV_ATTR_S
static int map2obj_VI_DEV_ATTR_S(hiobj_t* p_dst, klb::CMap& src)
{
    klb::CMap& r = src;
    VI_DEV_ATTR_S* p_cfg = (VI_DEV_ATTR_S*)p_dst->data;

    cmap_get_ENUM(r, "IntfMode", &p_cfg->enIntfMode);
    cmap_get_ENUM(r, "WorkMode", &p_cfg->enWorkMode);

    return 0;
}

static int obj2map_VI_DEV_ATTR_S(klb::CMap& dst, hiobj_t* p_src)
{
    klb::CMap& r = dst;
    const VI_DEV_ATTR_S* p_cfg = (const VI_DEV_ATTR_S*)p_src->data;

    r["IntfMode"] = (int64_t)p_cfg->enIntfMode;
    r["WorkMode"] = (int64_t)p_cfg->enWorkMode;

    klb::CArray a1;
    for (int i = 0; i < VI_COMPMASK_NUM; i++)
    {
        a1[i] = (int64_t)p_cfg->au32ComponentMask[i];
    }
    r["ComponentMask"] = a1;

    r["ScanMode"] = (int64_t)p_cfg->enScanMode;

    klb::CArray a2;
    for (int i = 0; i < VI_MAX_ADCHN_NUM; i++)
    {
        a2[i] = (int64_t)p_cfg->as32AdChnId[i];
    }
    r["AdChnId"] = a2;

    r["DataSeq"] = (int64_t)p_cfg->enDataSeq;

    return 0; 
}



//////////////////////////////////////////////////////////////////////////


int load_hiobj_vi(himpp_extension_t* p_ex)
{
    static hiobj_reg_t reg[] =
    {
        { "MPP_SYS_CONFIG_S",   sizeof(VI_DEV_ATTR_S),   map2obj_VI_DEV_ATTR_S ,  obj2map_VI_DEV_ATTR_S },

        { NULL, 0, NULL, NULL }
    };

    himpp_ex_add(p_ex, reg);

    return 1;
}
